<template>
	<view>
    <van-tabs v-model="activeName" color="#1989fa" title-active-color="#1989fa" swipeable>
      <van-tab :title="mhywName" name="mhyw">
        <van-list v-model="loading" :finished="finished" @load="onLoad">
          <van-cell v-for="item in mhywList" :title="item.infoTitle" :value="convertDate(item.publishDate)" @click="openDetail(item, 'news')" value-class="text-sm" />
        </van-list>
      </van-tab>
      <van-tab :title="mhxwName" name="mhxw">
        <van-list v-model="loading" :finished="finished" @load="onLoad">
          <van-cell v-for="item in mhxwList" :title="item.infoTitle" :value="convertDate(item.publishDate)" @click="openDetail(item, 'news')" value-class="text-sm" />
        </van-list>
      </van-tab>
      <van-tab :title="hlwzyName" name="hlwzy">
        <van-list v-model="loading" :finished="finished" @load="onLoad">
          <van-cell v-for="item in hlwzyList" :title="item.title" :value="convertDate(item.pushTime)" @click="openHlwzy(item.id)" value-class="text-sm">
          </van-cell>
        </van-list>
      </van-tab>
		</van-tabs>
	</view>
</template>

<script>
  export default {

		data() {
			return {
        userInfo: {},
        activeName: 'mhyw',
        mhywName: '局领导活动动态',
        mhywList: [],
        mhxwName: '行业动态',
        mhxwList: [],
        hlwzyName: '互联网摘要',
        hlwzyList: [],
        loading: false,
        finished: true,
        pageNum: 1,
        pageSize: 5,
			}
		},

    created() {
      this.userInfo = this.cache.get('userInfo')
    },

    mounted() {
      // 初始化数据
      this.getMhywList()
      this.getMhxwList()
      this.getHlwzyList()
    },

		methods: {
      // 民航要闻
      getMhywList() {
        let _this = this
        _this.$http({
          url: _this.$http.adornUrl(`/caac/oa/mhNewsType/queryMhNewsYwlist`),
          method: 'get',
          params: _this.$http.adornParams({
            'systemKey': this.userInfo.systemKey,
            'systemFlag': this.userInfo.systemFlag,
            'page': _this.pageNum,
            'rows': _this.pageSize,
          })
        }).then(({data}) => {
          if(data.code == 200) {
            _this.mhywList = data.data.rows
          }
        })
      },
      // 民航新闻
      getMhxwList() {
        let _this = this
        _this.$http({
          url: _this.$http.adornUrl(`/caac/oa/mhNewsType/getMhinfoIndustryNews`),
          method: 'get',
          params: _this.$http.adornParams({
            'systemKey': this.userInfo.systemKey,
            'systemFlag': this.userInfo.systemFlag,
            'page': _this.pageNum,
            'rows': _this.pageSize,
          })
        }).then(({data}) => {
          if(data.code == 200) {
            _this.mhxwList = data.data.rows
          }
        })
      },
      // 互联网摘要
      getHlwzyList() {
        let _this = this
        _this.$http({
          url: _this.$http.adornUrl(`/caac/oa/app/getInternetSummary`),
          method: 'get',
          params: _this.$http.adornParams({
            'page': _this.pageNum,
            'rows': _this.pageSize,
            'systemKey': this.userInfo.systemKey,
            'systemFlag': this.userInfo.systemFlag,
          })
        }).then(({data}) => {
          if(data.code == 200){
            if(data.data != null) {
              _this.hlwzyList = data.data.data.rows
            }
          }
        })
      },

      // 转换日期
      convertDate(publishDate) {
        if(publishDate != null && publishDate.length > 10) {
          publishDate = publishDate.substring(0, 10)
        }
        return publishDate
      },

      // 打开详情
      openDetail(item, type) {
        uni.navigateTo({
          url: '/pages/jgj/components/newsList/compo-detail?from=' + type,
          success: function(res) {
            // 通过eventChannel向被打开页面传送数据
            res.eventChannel.emit('acceptDataFromOpenerPage', item)
          }
        })
      },

      // 互联网摘要详情
      openHlwzy(id) {
        let _this = this
        _this.$http({
          url: _this.$http.adornUrl(`/caac/oa/app/getInternetSummaryDetails`),
          method: 'get',
          params: _this.$http.adornParams({
            'id': id,
            'systemKey': this.userInfo.systemKey,
            'systemFlag': this.userInfo.systemFlag,
          })
        }).then(({data}) => {
          if (data.code == 200) {
            let annexs = data.data.data.annexs
            // 新闻类型的跳转详情
            if (annexs == null || annexs.length == 0) {
              uni.navigateTo({
                url: '/pages/jgj/components/newsList/compo-detail?from=hlwzy',
                success: function(res) {
                  // 通过eventChannel向被打开页面传送数据
                  res.eventChannel.emit('acceptDataFromOpenerPage', data.data.data)
                }
              })
            } else {
              // 文件类型的用其他软件打开
              let attachId = annexs[0].attachId
              let attachName = annexs[0].annexName
              let attachType = attachName.split('.')[1]
              let openUrl = '/caac/platform/UploadChunkController/download?attachId=' + attachId +
                  '&systemKey=' + this.cache.get('userInfo').systemKey +
                  '&systemFlag=' + this.cache.get('userInfo').systemFlag
              _this.lx.openFileDetail(attachName, attachType, openUrl)
            }
          }
        })
      },

      onLoad() {

			},
		},
	}
</script>

<style>
	
</style>
